using System.Collections.Generic;

namespace InfiniTec.Threading
{
    public sealed class AsyncOperation<T>: AsyncOperation
    {
        private T _Result;

        public T Result { get { return _Result; } }

        private AdvanceAction OperationResultHandler(OperationAction obj)
        {
        	OperationResult<T> action = (OperationResult<T>) obj;

            _Result = action.Result;

            return AdvanceAction.ContinueSynchronous;
        }

        public AsyncOperation(IEnumerable<OperationAction> operation, object state) : base(operation, state)
        {
            InitializeOperationHandler();
        }

        private void InitializeOperationHandler()
        {
            OperationActionHandler.Add(typeof(OperationResult<T>), OperationResultHandler);
        }


        public AsyncOperation(string name, IEnumerable<OperationAction> operation, AsyncOperationTracker tracker, bool allowMultipleInvocations, object userState) : 
            base(name, operation, tracker, allowMultipleInvocations, userState)
        {
            InitializeOperationHandler();
        }
    }
}
